/*
 * @Author: earl 
 * @Date: 2018-12-16 22:05:04 
 * @Last Modified by: earl
 * @Last Modified time: 2018-12-16 22:06:06
 * @Describe:  数据库操作文件
 */

const mysql = require('mysql')

const pool = mysql.createPool({
  user: 'root',
  password: 'root1234',
  database: 'earl',
  host: 'localhost'
})

let query = function( sql, values ) {

  return new Promise(( resolve, reject ) => {
    pool.getConnection(function(err, connection) {
      if (err) {
        reject( err )
      } else {
        connection.query(sql, values, ( err, rows) => {

          if ( err ) {
            reject( err )
          } else {
            resolve( rows )
          }
          connection.release()
        })
      }
    })
  })

}

module.exports = {
  query
}
